﻿using KayakMes.Common.Dtos.ProductionDTO.Input;
using KayakMes.Common.Dtos.ProductionDTO.Output;
using KayakMes.Common.Result;
using KayakMes.ProcessManagement.Application.Production;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace KayakMes.ProcessManagement.Api.Controllers
{
    ///<summary>
    /// 生产订单
    /// </summary>`
    [Route("api/[controller]/[action]")]
    [ApiController]
    
    public class ProductionOrderController : ControllerBase
    {
        private readonly IProductionService _productionService;

        public ProductionOrderController(IProductionService productionService)
        {
            _productionService = productionService;
        }

        /// <summary>
        /// 添加生产订单
        /// </summary>
        /// <param name="input">生产订单输入模型</param>
        /// <returns>返回操作结果</returns>
        [HttpPost]
        public ApiResult<int> AddProductionOrder(ProductionOrderInput input)
        {
            return _productionService.AddProductionOrder(input);
        }

        /// <summary>
        /// 更新生产订单
        /// </summary>
        /// <param name="input">生产订单输入模型</param>
        /// <returns>返回操作结果</returns>
        [HttpPut]
        public ApiResult<int> UpdateProductionOrder(UpdateProductionOrderInput input)
        {
            return _productionService.UpdateProductionOrder(input);
        }

        /// <summary>
        /// 删除生产订单
        /// </summary>
        /// <param name="id">生产订单ID</param>
        /// <returns>返回操作结果</returns>
        [HttpDelete]
        public ApiResult<int> DeleteProductionOrder([FromQuery] long id)
        {
            return _productionService.DeleteProductionOrder(id);
        }

        /// <summary>
        /// 获取生产订单列表
        /// </summary>
        /// <param name="input">查询条件</param>
        /// <returns>返回分页结果</returns>
        [HttpGet]
        public ApiPaging<ProductionOrderOutput> GetProductionOrders([FromQuery] GetProductionOrderInput input)
        {
            return _productionService.GetProductionOrders(input);
        }

        /// <summary>
        /// 根据ID获取生产订单
        /// </summary>
        /// <param name="id">生产订单ID</param>
        /// <returns>返回操作结果</returns>
        [HttpGet]
        public ApiResult<ProductionOrderOutput> GetProductionOrderById([FromQuery] long id)
        {
            return _productionService.GetProductionOrderById(id);
        }
    }
}
